package task.manager;

import java.util.HashMap;
import java.util.Map;
import java.io.*;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

/**
 * The main activity class for the task manager.
 * 
 * @author Harrison Saylor, Aaron Mead, Marc Huet, Greg Ruskin
 * @version 1.0
 */
public class TaskManager2Activity extends Activity {

	private LoginFacade loginFacade;
	//private UserDataFacade userDataFacade;
	
	private EditText usernameBox;
	private EditText passwordBox;
	private TextView text;
	private Button btnLogin;
	private Button btnNewAccount;

	/**
	 * Called when the activity is started.
	 * 
	 * @param savedInstanceState
	 *            Any saved instance state.
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		loginFacade = LoginFacade.getInstance();
		
		usernameBox = (EditText)findViewById(R.id.username);
		passwordBox = (EditText)findViewById(R.id.password);
		text = (TextView)findViewById(R.id.textView1);
        btnLogin = (Button)findViewById(R.id.login_button);
        btnNewAccount = (Button)findViewById(R.id.register_button);
        
		btnLogin.setOnClickListener(new OnClickListener() {
			/**
			 * Response to clicking login.
			 */
			public void onClick(View v) {
				// Check Login
				String username = usernameBox.getText().toString();
				String password = passwordBox.getText().toString();
				if(loginFacade.isValid(username,password)){
					//text.setText("Valid Username and Password");
					UserDataFacade.setActiveUser(username);
					System.out.println("New Active User: " + username);
					Intent taskView = new Intent(getApplicationContext(),
							TaskViewActivity.class);
					startActivity(taskView);
					
				}
				
				
				
				/*Intent taskView = new Intent(getApplicationContext(),
						TaskViewActivity.class);
				startActivity(taskView);*/

			} // End of onClick method.
		}); // End of setOnClickListener.
		
		btnNewAccount.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				
				Intent nextScreen = new Intent(getApplicationContext(),
						CreateAccountActivity.class);
				startActivity(nextScreen);
			}
			
		});

	} // End of onCreate method.

} // End of TaskManagerActivity class.
    
